<template>
  <div class="goods-itme" >
    <div @click="itemClick">
        <img v-lazy="showImage" alt   />
    </div>
    <br />
    <div id="goods-info">
      <p>{{grassItem.title}}</p>

      <van-icon name="like-o"
                    size="14"
                    @click="likeClick(grassItem.id)"
                    :color="grassItem.likeFlag == 1?'#F1050A':''" />
      <span class="collect">{{grassItem.likeNum}}</span>
      <!-- <img class="sc-img" src="~assets/img/common/sc.png" alt />
      <span class="collect">{{grassItem.goodsFav}}</span> -->
    </div>
  </div>
</template>

<script>
export default {
  name: "GrassListItem",
  data(){
    return {
        num: 1
    }
  },
  props: {
    grassItem: {
      type: Object,
      default() {
        return {};
      }
    },
    inputData:{
      type:String,
      default(){
        return ''
      }
    }
  },
  //进行数据的处理
  filters:{
    sellCountFilter(value){
      let rselt =value;
      if(value > 10000){
        rselt = (rselt / 10000).toFixed(1) + '万'
      }
      return rselt
    }
  },
  computed: {
    showImage() {
      return this.grassItem.cover;
    }
  },
  methods: {
    itemClick() {
      if (this.grassItem.id) {
        this.$store.dispatch("addSearchGoods",this.inputData);
        this.$router.push("/mydetail/" + this.grassItem.goodsId);
      } else {
        return this.$toast.show("推荐商品暂未上架", 1200);
        //this.$router.push('/detail/' + this.goodsItem.item_id)
      }
    },

    likeClick(articleId) {
        console.log("like")
        this.$api.grass.LikeGrass({"articleId":articleId }).then(res=>{
            alert(res.data.data)
        })
    }
  }
};
</script>

<style scoped>
.goods-itme {
  position: relative;
  padding-bottom: 52px;
  width: 48%;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin-bottom: 5px;
}
.goods-itme img {
  width: 100%;
  border-radius: 5px;
}
#goods-info {
  font-size: 12px;
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  overflow: hidden;
  text-align: center;
}
#goods-info .sc-img {
  position: relative;
  left: 0px;
  top: 2px;
  width: 14px;
  height: 14px;
}
#goods-info p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}
#goods-info .price {
  color: var(--color-hight-text);
  margin-right: 20px;
}
#goods-info .collect {
  position: relative;
}
.old-price {
  color: gainsboro;
  margin-right: 10px;
  text-decoration: line-through;
   font-size: 10px;
  margin-left: 5px;
  float: left;
}
.goodsAre {
  font-size: 10px;
  margin-right: 5px;
  float: right;
}
.goods {
  height: 10px;
}
.goods-num{
  position: absolute;
  top:-85px;
  left: 0;
  right: 0;
  min-width: 30%;
  max-width: 40%;
  height: 1rem;
  line-height: 1rem;
  z-index: 3;
  color: white;
  text-align: left;
  background-size: 100%;
  font-size: .3rem;
  text-overflow: ellipsis;
  background: url('~assets/img/category/index.png')  0 no-repeat;
  padding-left: 5px;
}
</style>